package tuiLayer;

import ControlLayer.*;
import java.util.Scanner;

/**
 * Write a description of class MainMenuUI here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class MainMenuUI
{
    private DVDUI DVDUI;
    private PersonUI PersonUI;
    private LoanUI LoanUI;
    private String command;

    public MainMenuUI()
    {
        DVDUI = new DVDUI();
        PersonUI = new PersonUI();
        LoanUI = new LoanUI();
        command = null;
    }

    public void start()
    {
        boolean finished = false;
        while (!finished)
        {
            System.out.print ('\f');
            printMenu();
            reader();
            switch (command)
            {
                case "1":
                System.out.println();
                System.out.println("The system is shutting down.");
                finished = true;
                break;

                case "help": 
                System.out.println("\f");
                break;
                case "2": 
                System.out.println("\f");
                DVDUI.start(); break;
                case "3": 
                System.out.println("\f");
                PersonUI.personMenu(); break;
                case "4": 
                System.out.println("\f");
                LoanUI.start(); break;
            }
        }
    }
    
    //     public void start()
    //     {
    //         boolean finished = false;
    //         while (!finished)
    //         {
    //             System.out.print ('\f');
    //             printMenu();
    //             reader();
    //             if(command.equals("1"))
    //             {
    //                 System.out.println();
    //                 System.out.println("The system is shutting down.");
    //                 finished = true;
    //             }
    //             else if (command.equals("help"))
    //                 printMenu();
    //             else if(command.equals("2"))
    //                 DVDUI.start();
    //             else if(command.equals("3"))
    //                 PersonUI.personMenu();
    //             else if(command.equals("4"))
    //                 LoanUI.start();
    //         }
    //     }

    private void reader()
    {
        final String[] validCommands = {"1","2","3","4","help",};
        Scanner reader;
        String terminal;
        reader = new Scanner(System.in);
        boolean finished = false;
        while(!finished)
        {
            System.out.println();
            System.out.print("> ");
            terminal = reader.nextLine();
            for(int i = 0; i < validCommands.length; i++) 
            {
                if(validCommands[i].equals(terminal))
                {
                    finished = true;
                    command = terminal;
                }
            }
            if(finished == false)
                System.out.print("Try once again.");
        }
    }

    private void printMenu()
    {
        System.out.println();
        System.out.println("***  Main Menu  ***");
        System.out.println("(1) Quit.");
        System.out.println("(2) DVD Menu.");
        System.out.println("(3) Person Menu.");
        System.out.println("(4) Loan Menu.");
        System.out.println("Please select using the keypad");
    }
}